package com.rsjgroup.water.controller;

import com.rsjgroup.water.service.exception.ServiceException;
import com.rsjgroup.water.service.exception.UserNotFoundException;
import com.rsjgroup.water.service.exception.updateException;
import com.rsjgroup.water.util.JsonResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

public class BaseController {
    public final static Integer OK = 200;

    @ResponseBody
    @ExceptionHandler(ServiceException.class)
    public JsonResult<Void> handleException(Throwable e) {
        JsonResult<Void> jsonResult = new JsonResult<>(e);
        if (e instanceof updateException) {
            jsonResult.setState(4000);
            jsonResult.setMessage("用户更新头像产生了未知异常");
        } else if (e instanceof UserNotFoundException) {
            jsonResult.setState(4001);
            jsonResult.setMessage("用户信息未找到");
        }
        return jsonResult;
    }


    //使用session多次请求共享数据
}
